// pages/cut/cut.js
import {getImageURL} from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    videoSrc: "",
    videoSrc: "",
    duration: 26,
    sliderValue: [10,10],
    dpr: wx.getWindowInfo().pixelRatio,
    currentTab: '0',
    top: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.videoCtx = wx.createVideoContext('video');
    this.createSelectorQuery().select(".tabs").boundingClientRect(res => {
      this.setData({
        top: res.bottom
      })
    }).exec()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onTabsClick(e){
    console.log(e.detail)
    this.setData({
      currentTab: e.detail.value
    })
  },
  handleUpload(event){
    console.log("data",event)
    this.setData({
      videoSrc: getImageURL(event.detail.uri)
    })
  },
  
  addVideo(){
    wx.chooseMedia({
      count: 1,
      success:(res)=>{
        // console.log(res)
        const uri = res.tempFiles[0].tempFilePath
        this.setData({
          videoSrc: uri
        })
        wx.getVideoInfo({
          src: uri,
          success:(res)=>{
            // console.log('videoInfo=====>',res)
            this.setData({
              duration: res.duration
            })
          }
        })

        // this.videoCtx = wx.createVideoContext('video');
        // this.canvasCtx = wx.createCanvasContext('myCanvas');
    
      }
    })
  },
  captureFrameAtTime(time) {
    console.log("开始截图")
    this.videoCtx.seek(time); // 跳转到指定时间
  },
  handleSendDM(event){
    wx.createVideoContext('video').sendDanmu({
      text: event.detail.text,
      color:event.detail.color
    })
  },
  handleUpdateUri(option){
    console.log("option=======>",option)
    this.setData({
      videoSrc: getImageURL(option.detail.newFileName)
    })
  },
  handleUpdate(option){
    this.setData({
      videoSrc: getImageURL(option.detail.uri)
    })
  }
})